package com.shuang.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shuang.common.PageObject;
import com.shuang.pojo.DbGoods;
import com.shuang.pojo.ExtendDbGoods;
import com.shuang.pojo._ExtendDbGoods;
import com.shuang.service.DbGoodsService;

@Controller
@RequestMapping("/goods")
public class DbGoodsHanlder {
	
	@Resource(name="dbGoodsService")
	private DbGoodsService  dbGoodsService;
	
	@RequestMapping("/addGoods")
	@ResponseBody
	public Map<String,Object> addGoods(ExtendDbGoods dbGoods) throws Exception{
		if(dbGoods==null){
			Map<String,Object> map=new HashMap<String, Object>();
			map.put("status", 403);
			map.put("info", "参数不完整");
			return map;
		}
		return dbGoodsService.insertGoods(dbGoods);
	}
	
	
	@RequestMapping("/getGoodsList")
	@ResponseBody
	public PageObject<_ExtendDbGoods> selectGoodsList(@RequestParam(value="page",defaultValue="1") int page, @RequestParam(value="rows",defaultValue="10")int rows){
		return dbGoodsService.selectGoodsList(page,rows);
	}
	
	@RequestMapping("/examOK")//上架商品，将状态修改为3
	@ResponseBody
	public Map<String,Object> examOK(@RequestParam(value="id")Long gId){
		if(gId==null){
			Map<String,Object> map=new HashMap<String, Object>();
			map.put("status", 403);
			map.put("data", "参数不完整");
			return map;
		}
		return dbGoodsService.updateGoodsStatusById(gId,(short)2);
	}
	
	@RequestMapping("/groundingitGoodsById")//上架商品，将状态修改为3
	@ResponseBody
	public Map<String,Object> groundingitGoodsById(@RequestParam(value="id")Long gId){
		if(gId==null){
			Map<String,Object> map=new HashMap<String, Object>();
			map.put("status", 403);
			map.put("data", "参数不完整");
			return map;
		}
		return dbGoodsService.updateGoodsStatusById(gId,(short)3);
	}
	
	
	@RequestMapping("/undercarriageitGoodsById")//下架商品，将状态修改为4
	@ResponseBody
	public Map<String,Object>  undercarriageitGoodsById(@RequestParam(value="id")Long gId){
		if(gId==null){
			Map<String,Object> map=new HashMap<String, Object>();
			map.put("status", 403);
			map.put("data", "参数不完整");
			return map;
		}
		return dbGoodsService.updateGoodsStatusById(gId,(short)4);
	}
	@RequestMapping("/updateGoods")
	@ResponseBody
	public  Map<String,Object> updateGoods(DbGoods dbGoods){
		if(dbGoods==null){
			Map<String,Object> map=new HashMap<String, Object>();
			map.put("status", 403);
			map.put("data", "参数不完整");
			return map;
		}
		return dbGoodsService.updateGoods(dbGoods);
	}
	@RequestMapping("/front/frontSelectBypage")
	@ResponseBody
	public List<DbGoods> frontSelectBypage(@RequestParam(defaultValue="1",value="page")int page,@RequestParam(defaultValue="8",value="rows")int rows){
		return dbGoodsService.selectGoodsListStatusIOK(page, rows).getRows();
	}
}
